/**
 */
package generalbookings.impl;

import generalbookings.BookedOptions;
import generalbookings.Booking;
import generalbookings.GeneralbookingsPackage;
import generalbookings.Location;
import generalbookings.Property;
import generalbookings.Resources;
import generalbookings.ServiceTime;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Booking</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link generalbookings.impl.BookingImpl#getId <em>Id</em>}</li>
 *   <li>{@link generalbookings.impl.BookingImpl#getResource <em>Resource</em>}</li>
 *   <li>{@link generalbookings.impl.BookingImpl#getOptions <em>Options</em>}</li>
 *   <li>{@link generalbookings.impl.BookingImpl#getLocation <em>Location</em>}</li>
 *   <li>{@link generalbookings.impl.BookingImpl#getBookingProperties <em>Booking Properties</em>}</li>
 *   <li>{@link generalbookings.impl.BookingImpl#getTime <em>Time</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class BookingImpl extends EObjectImpl implements Booking {
	/**
	 * The default value of the '{@link #getId() <em>Id</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getId()
	 * @generated
	 * @ordered
	 */
	protected static final long ID_EDEFAULT = 0L;

	/**
	 * The cached value of the '{@link #getId() <em>Id</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getId()
	 * @generated
	 * @ordered
	 */
	protected long id = ID_EDEFAULT;

	/**
	 * The cached value of the '{@link #getResource() <em>Resource</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getResource()
	 * @generated
	 * @ordered
	 */
	protected Resources resource;

	/**
	 * The cached value of the '{@link #getOptions() <em>Options</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getOptions()
	 * @generated
	 * @ordered
	 */
	protected EList<BookedOptions> options;

	/**
	 * The cached value of the '{@link #getLocation() <em>Location</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getLocation()
	 * @generated
	 * @ordered
	 */
	protected Location location;

	/**
	 * The cached value of the '{@link #getBookingProperties() <em>Booking Properties</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getBookingProperties()
	 * @generated
	 * @ordered
	 */
	protected EList<Property> bookingProperties;

	/**
	 * The cached value of the '{@link #getTime() <em>Time</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getTime()
	 * @generated
	 * @ordered
	 */
	protected ServiceTime time;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected BookingImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return GeneralbookingsPackage.Literals.BOOKING;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public long getId() {
		return id;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setId(long newId) {
		long oldId = id;
		id = newId;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, GeneralbookingsPackage.BOOKING__ID, oldId, id));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Resources getResource() {
		if (resource != null && resource.eIsProxy()) {
			InternalEObject oldResource = (InternalEObject)resource;
			resource = (Resources)eResolveProxy(oldResource);
			if (resource != oldResource) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, GeneralbookingsPackage.BOOKING__RESOURCE, oldResource, resource));
			}
		}
		return resource;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Resources basicGetResource() {
		return resource;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setResource(Resources newResource) {
		Resources oldResource = resource;
		resource = newResource;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, GeneralbookingsPackage.BOOKING__RESOURCE, oldResource, resource));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<BookedOptions> getOptions() {
		if (options == null) {
			options = new EObjectContainmentEList<BookedOptions>(BookedOptions.class, this, GeneralbookingsPackage.BOOKING__OPTIONS);
		}
		return options;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Location getLocation() {
		return location;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetLocation(Location newLocation, NotificationChain msgs) {
		Location oldLocation = location;
		location = newLocation;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, GeneralbookingsPackage.BOOKING__LOCATION, oldLocation, newLocation);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setLocation(Location newLocation) {
		if (newLocation != location) {
			NotificationChain msgs = null;
			if (location != null)
				msgs = ((InternalEObject)location).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - GeneralbookingsPackage.BOOKING__LOCATION, null, msgs);
			if (newLocation != null)
				msgs = ((InternalEObject)newLocation).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - GeneralbookingsPackage.BOOKING__LOCATION, null, msgs);
			msgs = basicSetLocation(newLocation, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, GeneralbookingsPackage.BOOKING__LOCATION, newLocation, newLocation));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Property> getBookingProperties() {
		if (bookingProperties == null) {
			bookingProperties = new EObjectContainmentEList<Property>(Property.class, this, GeneralbookingsPackage.BOOKING__BOOKING_PROPERTIES);
		}
		return bookingProperties;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public ServiceTime getTime() {
		if (time != null && time.eIsProxy()) {
			InternalEObject oldTime = (InternalEObject)time;
			time = (ServiceTime)eResolveProxy(oldTime);
			if (time != oldTime) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, GeneralbookingsPackage.BOOKING__TIME, oldTime, time));
			}
		}
		return time;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public ServiceTime basicGetTime() {
		return time;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setTime(ServiceTime newTime) {
		ServiceTime oldTime = time;
		time = newTime;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, GeneralbookingsPackage.BOOKING__TIME, oldTime, time));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case GeneralbookingsPackage.BOOKING__OPTIONS:
				return ((InternalEList<?>)getOptions()).basicRemove(otherEnd, msgs);
			case GeneralbookingsPackage.BOOKING__LOCATION:
				return basicSetLocation(null, msgs);
			case GeneralbookingsPackage.BOOKING__BOOKING_PROPERTIES:
				return ((InternalEList<?>)getBookingProperties()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case GeneralbookingsPackage.BOOKING__ID:
				return getId();
			case GeneralbookingsPackage.BOOKING__RESOURCE:
				if (resolve) return getResource();
				return basicGetResource();
			case GeneralbookingsPackage.BOOKING__OPTIONS:
				return getOptions();
			case GeneralbookingsPackage.BOOKING__LOCATION:
				return getLocation();
			case GeneralbookingsPackage.BOOKING__BOOKING_PROPERTIES:
				return getBookingProperties();
			case GeneralbookingsPackage.BOOKING__TIME:
				if (resolve) return getTime();
				return basicGetTime();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case GeneralbookingsPackage.BOOKING__ID:
				setId((Long)newValue);
				return;
			case GeneralbookingsPackage.BOOKING__RESOURCE:
				setResource((Resources)newValue);
				return;
			case GeneralbookingsPackage.BOOKING__OPTIONS:
				getOptions().clear();
				getOptions().addAll((Collection<? extends BookedOptions>)newValue);
				return;
			case GeneralbookingsPackage.BOOKING__LOCATION:
				setLocation((Location)newValue);
				return;
			case GeneralbookingsPackage.BOOKING__BOOKING_PROPERTIES:
				getBookingProperties().clear();
				getBookingProperties().addAll((Collection<? extends Property>)newValue);
				return;
			case GeneralbookingsPackage.BOOKING__TIME:
				setTime((ServiceTime)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case GeneralbookingsPackage.BOOKING__ID:
				setId(ID_EDEFAULT);
				return;
			case GeneralbookingsPackage.BOOKING__RESOURCE:
				setResource((Resources)null);
				return;
			case GeneralbookingsPackage.BOOKING__OPTIONS:
				getOptions().clear();
				return;
			case GeneralbookingsPackage.BOOKING__LOCATION:
				setLocation((Location)null);
				return;
			case GeneralbookingsPackage.BOOKING__BOOKING_PROPERTIES:
				getBookingProperties().clear();
				return;
			case GeneralbookingsPackage.BOOKING__TIME:
				setTime((ServiceTime)null);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case GeneralbookingsPackage.BOOKING__ID:
				return id != ID_EDEFAULT;
			case GeneralbookingsPackage.BOOKING__RESOURCE:
				return resource != null;
			case GeneralbookingsPackage.BOOKING__OPTIONS:
				return options != null && !options.isEmpty();
			case GeneralbookingsPackage.BOOKING__LOCATION:
				return location != null;
			case GeneralbookingsPackage.BOOKING__BOOKING_PROPERTIES:
				return bookingProperties != null && !bookingProperties.isEmpty();
			case GeneralbookingsPackage.BOOKING__TIME:
				return time != null;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (id: ");
		result.append(id);
		result.append(')');
		return result.toString();
	}

} //BookingImpl
